#ifndef SQLITE3_H
#define SQLITE3_H

#ifdef __cplusplus
extern "C" {
#endif

/* SQLite版本信息 */
#define SQLITE_VERSION        "3.40.0"
#define SQLITE_VERSION_NUMBER 3040000
#define SQLITE_SOURCE_ID      "2023-02-21 17:30:00 0000000000000000000000000000000000000000"

/* 结果代码 */
#define SQLITE_OK           0   /* 成功 */
#define SQLITE_ERROR        1   /* SQL错误或缺失数据库 */
#define SQLITE_INTERNAL     2   /* SQLite内部逻辑错误 */
#define SQLITE_PERM         3   /* 拒绝访问 */
#define SQLITE_ABORT        4   /* 回调例程请求中止 */
#define SQLITE_BUSY         5   /* 数据库文件被锁定 */
#define SQLITE_LOCKED       6   /* 数据库中的表被锁定 */
#define SQLITE_NOMEM        7   /* 内存分配失败 */
#define SQLITE_READONLY     8   /* 尝试写入只读数据库 */
#define SQLITE_INTERRUPT    9   /* 操作被中断 */
#define SQLITE_IOERR       10   /* 磁盘I/O错误 */
#define SQLITE_CORRUPT     11   /* 数据库磁盘映像损坏 */
#define SQLITE_NOTFOUND    12   /* 未知操作码 */
#define SQLITE_FULL        13   /* 数据库满 */
#define SQLITE_CANTOPEN    14   /* 无法打开数据库文件 */
#define SQLITE_PROTOCOL    15   /* 数据库锁定协议错误 */
#define SQLITE_EMPTY       16   /* 数据库为空 */
#define SQLITE_SCHEMA      17   /* 数据库模式已更改 */
#define SQLITE_TOOBIG      18   /* 字符串或BLOB太大 */
#define SQLITE_CONSTRAINT  19   /* 违反约束 */
#define SQLITE_MISMATCH    20   /* 数据类型不匹配 */
#define SQLITE_MISUSE      21   /* 库使用不当 */
#define SQLITE_NOLFS       22   /* 使用OS功能不支持的操作 */
#define SQLITE_AUTH        23   /* 授权拒绝 */
#define SQLITE_FORMAT      24   /* 辅助数据库格式错误 */
#define SQLITE_RANGE       25   /* 绑定参数超出范围 */
#define SQLITE_NOTADB      26   /* 打开的文件不是数据库文件 */
#define SQLITE_NOTICE      27   /* 来自sqlite3_log()的通知 */
#define SQLITE_WARNING     28   /* 来自sqlite3_log()的警告 */
#define SQLITE_ROW         100  /* sqlite3_step()已准备好一行 */
#define SQLITE_DONE        101  /* sqlite3_step()已完成执行 */

/* 扩展结果代码 */
#define SQLITE_IOERR_READ              (SQLITE_IOERR | (1<<8))
#define SQLITE_IOERR_SHORT_READ        (SQLITE_IOERR | (2<<8))
#define SQLITE_IOERR_WRITE             (SQLITE_IOERR | (3<<8))
#define SQLITE_IOERR_FSYNC             (SQLITE_IOERR | (4<<8))
#define SQLITE_IOERR_DIR_FSYNC         (SQLITE_IOERR | (5<<8))
#define SQLITE_IOERR_TRUNCATE          (SQLITE_IOERR | (6<<8))
#define SQLITE_IOERR_FSTAT             (SQLITE_IOERR | (7<<8))
#define SQLITE_IOERR_UNLOCK            (SQLITE_IOERR | (8<<8))
#define SQLITE_IOERR_RDLOCK            (SQLITE_IOERR | (9<<8))
#define SQLITE_IOERR_DELETE            (SQLITE_IOERR | (10<<8))

/* 基本类型和常量 */
typedef struct sqlite3 sqlite3;
typedef struct sqlite3_stmt sqlite3_stmt;
typedef long long int sqlite3_int64;
typedef unsigned long long int sqlite3_uint64;
typedef sqlite3_int64 sqlite_int64;
typedef sqlite3_uint64 sqlite_uint64;

#define SQLITE_STATIC      ((void(*)(void *))0)
#define SQLITE_TRANSIENT   ((void(*)(void *))-1)

/* 核心函数 */
int sqlite3_open(const char *filename, sqlite3 **ppDb);
int sqlite3_open_v2(const char *filename, sqlite3 **ppDb, int flags, const char *zVfs);
int sqlite3_close(sqlite3 *db);
int sqlite3_exec(sqlite3 *db, const char *sql, int (*callback)(void*,int,char**,char**), void *arg, char **errmsg);
int sqlite3_prepare_v2(sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt **ppStmt, const char **pzTail);
int sqlite3_bind_text(sqlite3_stmt *pStmt, int i, const char *zData, int nData, void (*xDel)(void*));
int sqlite3_bind_int(sqlite3_stmt *pStmt, int i, int iValue);
int sqlite3_bind_int64(sqlite3_stmt *pStmt, int i, sqlite3_int64 iValue);
int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue);
int sqlite3_bind_null(sqlite3_stmt *pStmt, int i);
int sqlite3_step(sqlite3_stmt *pStmt);
int sqlite3_finalize(sqlite3_stmt *pStmt);
int sqlite3_reset(sqlite3_stmt *pStmt);
int sqlite3_column_count(sqlite3_stmt *pStmt);
const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N);
int sqlite3_column_type(sqlite3_stmt *pStmt, int iCol);
int sqlite3_column_int(sqlite3_stmt *pStmt, int iCol);
sqlite3_int64 sqlite3_column_int64(sqlite3_stmt *pStmt, int iCol);
double sqlite3_column_double(sqlite3_stmt *pStmt, int iCol);
const unsigned char *sqlite3_column_text(sqlite3_stmt *pStmt, int iCol);
const void *sqlite3_column_blob(sqlite3_stmt *pStmt, int iCol);
int sqlite3_column_bytes(sqlite3_stmt *pStmt, int iCol);
const char *sqlite3_errmsg(sqlite3 *db);
void sqlite3_free(void *p);

/* 内存分配函数 */
void *sqlite3_malloc(int);
void *sqlite3_realloc(void*, int);

#ifdef __cplusplus
}  /* End of the 'extern "C"' block */
#endif

#endif /* SQLITE3_H */
